using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class UImNavigation : MonoBehaviour {
	
	public GameObject targetNavBar;
	
	protected List<UImViewor> listViewors = new List<UImViewor>();
	
	public void pushViewor(GameObject go) {
		int count = listViewors.Count;
		if(count > 0) {
			listViewors[count - 1].gameObject.SetActive(false);
		}
		
		UImViewor viewor = go.GetComponent<UImViewor>();
		if(viewor == null) {
			viewor = go.AddComponent<UImViewor>();
		}
		
		listViewors.Add(viewor);
		go.transform.parent = gameObject.transform;
		go.transform.localScale = new Vector3(0.6f, 0.6f, 1f);
		go.SetActive(true);
	}
	
	public UImViewor popViewor() {
		int count = listViewors.Count;
		if(count > 0) {
			UImViewor viewor = listViewors[count - 1];
			Destroy(viewor.gameObject);
			//viewor.gameObject.transform.parent = null;
			
			if(count > 1) {
				listViewors[count - 2].gameObject.SetActive(true);
			}
			
			listViewors.RemoveAt(count - 1);
			
			return viewor;
		}
		
		return null;
	}
	
}
